package com.pdwl.common.dtos;

import com.github.pagehelper.PageInfo;
import com.pdwl.common.enums.AppHttpCodeEnum;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class PageResponseResult<T> extends ResponseResult<T> implements Serializable {
    private Integer currentPage;
    private Integer size;
    private Long total;

    public PageResponseResult(Integer currentPage, Integer size, Long total) {
        this.currentPage = currentPage;
        this.size = size;
        this.total = total;
    }

    public PageResponseResult() {

    }

    public static <K> PageResponseResult<List<K>> success(PageInfo<K> pageInfo) {
        AppHttpCodeEnum enums = AppHttpCodeEnum.SUCCESS;
        PageResponseResult<List<K>> pageResponseResult =
                new PageResponseResult<>(pageInfo.getPageNum(), pageInfo.getSize(), pageInfo.getTotal());
        pageResponseResult.ok(enums.getCode(), pageInfo.getList(), enums.getErrorMessage());
        return pageResponseResult;
    }

    public static <K> PageResponseResult<List<K>> error(AppHttpCodeEnum enums) {
        return PageResponseResult.error(enums);
    }

}
